package com.cw.spider;

import com.cw.spider.queue.Myqueue;
import com.cw.spider.utils.IPPool;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;

@SpringBootApplication

public class SpiderApplication implements CommandLineRunner {

    @Autowired
    Myqueue myqueue;
    @Value("${processTaskCore.count}")
    private int taskCore;


    public static void main(String[] args) {
        SpringApplication.run(SpiderApplication.class, args);
    }

    @Override
    public void run(String... args) throws Exception {
        ThreadFactory threadFactory = new ThreadFactoryBuilder()
            .setNameFormat("spider task - %d").build();
        ExecutorService workersPool = Executors.newFixedThreadPool(taskCore,threadFactory);

        myqueue.setWorkersPool(workersPool);
        myqueue.run();
    }
}
